package com.dg.cuckoo.admin.action.compilation;

import com.dg.cuckoo.admin.dto.compilation.GovernmentMoneyDto;
import com.dg.cuckoo.admin.service.GovernmentMoneyService;
import com.dg.cuckoo.common.utils.PageModel;
import com.dg.cuckoo.core.BaseController;
import com.dg.cuckoo.core.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 制度汇编-政府投资
 */
@RestController
@RequestMapping("/compilation/governmentMoney")
public class GovernmentMoney extends BaseController {

    @Autowired
    private GovernmentMoneyService service;

    /**
     * 新建
     */
    @PostMapping("save")
    public JsonResult<Void> save(GovernmentMoneyDto dto, MultipartFile[] files) throws Exception {
        service.save(dto,files);
        return new JsonResult<>(OK);
    }

    /**
     * 删除
     */
    @PostMapping("delect/{id}")
    public JsonResult<Void> delect(@PathVariable String id){
        service.delect(id);
        return new JsonResult<>(OK);
    }

    /**
     * 分页
     * @param page 页
     * @param pageSize 页数
     * @return
     */
    @PostMapping("page/{page}/{pageSize}")
    public JsonResult<PageModel> page(@PathVariable Integer page, @PathVariable Integer pageSize){
        PageModel data = service.page(page, pageSize);
        return new JsonResult<>(OK,data);
    }

    /**
     * 点击发行文字显示全部数据
     */
    @PostMapping("openInfo/{id}")
    public JsonResult<GovernmentMoneyDto> openInfo(@PathVariable String id){
        GovernmentMoneyDto data = service.openInfo(id);
        return new JsonResult<>(OK,data);
    }

    /**
     * 点击名称显示内容框
     */
    @PostMapping("openContent/{id}")
    public JsonResult<String> openContent(@PathVariable String id){
        String data = service.openContent(id);
        return new JsonResult<>(OK,data);
    }

    /**
     * 保存
     */
    @PostMapping("updata/{id}")
    public JsonResult<Void> update(@PathVariable String id,GovernmentMoneyDto dto, MultipartFile[] files) throws Exception {
        service.update(id,dto,files);
        return new JsonResult<>(OK);
    }
}
